package crypto

import (
	"blueprint-crypto/internal/util"
	"fmt"
	"gopkg.in/yaml.v3"
	"io/ioutil"
	"log"
)

// 批量加密
func BatchRSA_Encrypt_yaml(rootPath string, pempath string, keyword string) {
	if !util.PathExists(rootPath) {
		panic(rootPath + "路径不存在，请检查")
	}
	if !util.PathExists(pempath) {
		panic(pempath + "文件不存在，请检查")
	}
	plainFiles := util.Getfilepath(rootPath, keyword)
	for _, plainFile := range plainFiles {
		if util.IsFile(plainFile) {
			data := util.Parse_yaml(plainFile)
			new_data := util.WalkEncryptoYaml(data, pempath)
			fmt.Println(new_data)
			new_data2, err := yaml.Marshal(new_data)
			if err != nil {
				log.Fatal(err)
			}
			err2 := ioutil.WriteFile(plainFile, new_data2, 0644)

			if err2 != nil {
				log.Fatal(err2)
			}
			fmt.Println(plainFile, "加密完成")
		}
	}
}
